--[[
* 能量变更后
*]]
---@class BuffEffect75 : BaseBuffEffect
BuffEffect75 = ClientFight.CreateClass("BuffEffect75", ClientFight.BaseBuffEffect)
local t = BuffEffect75
---@param fight Fight
---@param buff FighterBuff

function t:action(fight, buff, ...)
    local result = parameters[3];
    if (result:isDamage()) then
        return IBuffEffect.FAIL;
    end
    if (not AttackUtils.isDamage(result.state)) then
        return IBuffEffect.FAIL;
    end
    local target = parameters[1];
    local buffEffectValue = buff.buffBean.f_BuffEffectValue;
    local x = buffEffectValue[2];
    local y = buffEffectValue[3];

    local realDamage = (long)(result.damage * toRatio(buffEffectValue[1]));
    if (realDamage < 1) then
        return IBuffEffect.FAIL;
    end
    local enemyList = FighterUtils.getOursBy(target, true, nil);
    for k, enemy in pairs(enemyList) do
        if table.contains(enemy.totalSign.sign,FighterSignEnum.TAG_1006) then
            goto continue;
        end
        local yDis = toRatio(y) / 2;
        if (enemy.position.x < target.position.x - yDis or enemy.position.x > target.position.x + yDis) then
            goto continue;
        end
        local currDirection = FighterUtils.leftOrRight(buff.target, target);

        local enemyX = enemy.position.x;--被溅射的人的位置
        local targetX = target.position.x;--敌人站的位置
        local xPos = targetX + Utils.toRatio(x) * currDirection;
        local minX = Math.min(targetX, xPos);
        local maxX = Math.max(targetX, xPos);
        if (minX > enemyX or enemyX > maxX) then
            goto continue;
        end
        --在溅射范围里的敌人, 被溅射伤害
        DamageManager.setFighterHp(fight, enemy, buff.target, nil, DamageResultTypeEnum.NORMAL
        , -realDamage, enemy.hp - realDamage, true, true, true);
        DamageManager.recordStatisticsValue(buff.target, FightStatisticsEnum.ATTACK, realDamage);

        --LogUtil.info(fight, ()-> "[" + fight.getFrame() + "][EFFECT]Fighter " + buff.target.getFighterId() + " Buff"
        --+ buff.getModelId() + " 触发溅射伤害给 " + enemy.getFighterId() +"  伤害值 = "+realDamage);
        :: continue ::
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, parameters);
end

t.New()